﻿namespace NMortgage.UI.Tests
{
    using System;

    using Microsoft.VisualStudio.TestTools.UnitTesting;

    using NMortgage.UI.Model;

    /// <summary>
    ///This is a test class for InterestParameterTest and is intended
    ///to contain all InterestParameterTest Unit Tests
    ///</summary>
    [TestClass]
    public class InterestParameterTest
    {
        #region Methods

        /// <summary>
        ///A test for Years
        ///</summary>
        [TestMethod]
        public void DescriptionContainsNumbersTest()
        {
            int one = 1;
            int thirteen = 13;

            var target = new InterestParameter(DistributionType.FixedRate) { Months = one, Years = one };
            ((FixedRate)target.Distribution).Rate = one;

            int actual = target.Description.IndexOf(one.ToString());
            int notExpected = -1;

            Assert.AreNotEqual(notExpected,actual);

            actual = target.Description.IndexOf(thirteen.ToString());
            notExpected = -1;

            Assert.AreNotEqual(notExpected, actual);
        }

        /// <summary>
        ///A test for Years
        ///</summary>
        [TestMethod]
        public void DescriptionNotNullTest()
        {
            var target = new InterestParameter(DistributionType.FixedRate) { Months = 1, Years = 1 };
            ((FixedRate)target.Distribution).Rate = 1;

            string actual = target.Description;
            Assert.IsNotNull(target.Description);
        }

        /// <summary>
        ///A test for Distribution
        ///</summary>
        [TestMethod]
        public void InterestRateTest_Beta()
        {
            var target = new InterestParameter(DistributionType.BetaDistribution);
            var actual = target.Distribution;
            Type expectedType = typeof(BetaDistribution);
            Assert.IsInstanceOfType(actual, expectedType);
        }

        /// <summary>
        ///A test for Distribution
        ///</summary>
        [TestMethod]
        public void InterestRateTest_Fixed()
        {
            var target = new InterestParameter(DistributionType.FixedRate);
            var actual = target.Distribution;
            Type expectedType = typeof(FixedRate);
            Assert.IsInstanceOfType(actual, expectedType);
        }

        /// <summary>
        ///A test for Distribution
        ///</summary>
        [TestMethod]
        public void InterestRateTest_Normal()
        {
            var target = new InterestParameter(DistributionType.NormalDistribution);
            var actual = target.Distribution;
            Type expectedType = typeof(NormalDistribution);
            Assert.IsInstanceOfType(actual, expectedType);
        }

        /// <summary>
        ///A test for Distribution
        ///</summary>
        [TestMethod]
        public void InterestRateTest_Uniform()
        {
            var target = new InterestParameter(DistributionType.UniformDistribution);
            var actual = target.Distribution;
            Type expectedType = typeof(UniformDistribution);
            Assert.IsInstanceOfType(actual, expectedType);
        }

        /// <summary>
        ///A test for Months
        ///</summary>
        [TestMethod]
        public void MonthsTest()
        {
            var target = new InterestParameter();
            int expected = 1;
            int actual;
            target.Months = expected;
            actual = target.Months;
            Assert.AreEqual<int>(expected, actual);
        }

        [TestMethod]
        public void RateTypeTest()
        {
            var target = new InterestParameter();
            DistributionType expected = DistributionType.FixedRate;
            DistributionType actual = target.DistributionType;
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for TotalOffsetInMonths
        ///</summary>
        [TestMethod]
        public void TotalDurationInMonths0Years13MonthsTest()
        {
            var target = new InterestParameter() { Months = 13, Years = 0 };
            int actual = target.TotalDurationInMonths;
            Assert.AreEqual<int>(actual, 13);
        }

        /// <summary>
        ///A test for TotalOffsetInMonths
        ///</summary>
        [TestMethod]
        public void TotalDurationInMonths0YearsTest()
        {
            var target = new InterestParameter() { Months = 1, Years = 0 };
            int actual = target.TotalDurationInMonths;
            Assert.AreEqual<int>(actual, 1);
        }

        /// <summary>
        ///A test for TotalOffsetInMonths
        ///</summary>
        [TestMethod]
        public void TotalDurationInMonths4Years13MonthsTest()
        {
            var target = new InterestParameter() { Months = 13, Years = 4 };
            int actual = target.TotalDurationInMonths;
            Assert.AreEqual<int>(actual, (4 * 12) + 13);
        }

        /// <summary>
        ///A test for Years
        ///</summary>
        [TestMethod]
        public void YearsTest()
        {
            var target = new InterestParameter();
            int expected = 1;
            int actual;
            target.Years = expected;
            actual = target.Years;
            Assert.AreEqual<int>(expected, actual);
        }

        #endregion Methods
    }
}